------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_7
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/prepare/unrate.log
  log type:  text
 opened on:  27 Nov 2024, 13:52:49

. **************************************************************************
. * unrate.do
. * Makes time series of national unemployment rate and panel of state UR.
. *
. *Updated:
. * JR, 4/30/18: Update input data, and cut things off at end of 2017
. * NR, 9/10/18: Update input data, data extends through July 2018
. * NR, 4/02/19: Update input data, extend data through 2018 - drop if 2019
. * NG, 08/22/19: Update input data, extend data through July 2019
. * JR, 4/14/2020, with data through 3/2020                       
. 
. **************************************************************************
. 
. cap project, doinfo

. if _rc==0 {
.    local pdir "`r(pdir)'"                                                     // the project's main dir.
.    local dofile "`r(dofile)'"                                                 // do-file's stub name
.    local sig {bind:{hi:[`dofile'.dta. RP : `dofile'.do, `c(current_date)']}}  // a signature in notes
.    local doasproject=1
. }

. else {
.    local pdir "~/GRscarring"
.    local dofile "unrate"
.    local doasproject=0
. }

. 
. set more off

. local rootdir "`pdir'"

. local thisdir "`pdir'"

. 
. local prepdata "`pdir'/scratch"

. local rawdata "`pdir'/rawdata"

. local output "`pdir'/results"

. 
. ***************************************************************************************************************
. ***************************************************************************************************************
. *** 0.1 LOAD NATIONAL UNEMPLOYMENT DATA ***
. *******************************************
. 
. * National - monthly
. * Downloaded from https://data.bls.gov/cgi-bin/srgate
. * From BLS website -- series LNS14000000 :
. * All years, original data value, CSV
. * From BLS website -- series LNU04000000 :
. * All years, original data value, CSV, include annual averages
. * Most recent download 8/25/2019
. if `doasproject'==1 project, original(`rawdata'/lns14000000.csv)
project GRscar_erratum > do-file uses original: "/scratch/public/jr_ra/GRscarring2024/erratum/rawdata/lns14000000.csv" filesig(45487
> 6154:3914)

. import delimited using "`rawdata'/lns14000000.csv" , clear varnames(1)
(13 vars, 73 obs)

. rename (jan-dec) ur#, addnumber

. foreach v of varlist ur* {
  2.   destring `v', replace
  3. }
ur1 already numeric; no replace
ur2 already numeric; no replace
ur3 already numeric; no replace
ur4: all characters numeric; replaced as double
(1 missing value generated)
ur5: all characters numeric; replaced as double
(1 missing value generated)
ur6: all characters numeric; replaced as double
(1 missing value generated)
ur7: all characters numeric; replaced as double
(1 missing value generated)
ur8: all characters numeric; replaced as double
(1 missing value generated)
ur9: all characters numeric; replaced as double
(1 missing value generated)
ur10: all characters numeric; replaced as double
(1 missing value generated)
ur11: all characters numeric; replaced as double
(1 missing value generated)
ur12: all characters numeric; replaced as double
(1 missing value generated)

. reshape long ur, i(year) j(month)
(j = 1 2 3 4 5 6 7 8 9 10 11 12)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations               73   ->   876         
Number of variables                  13   ->   3           
j variable (12 values)                    ->   month
xij variables:
                       ur1 ur2 ... ur12   ->   ur
-----------------------------------------------------------------------------

. gen yearmo=ym(year, month)

. keep yearmo ur

. drop if ur==.
(9 observations deleted)

. rename ur ur_nat_s

. tempfile ur_s

. save `ur_s'
file /tmp/St2868349.000004 saved as .dta format

. 
. 
. if `doasproject'==1 project, original(`rawdata'/lnu04000000.csv)
project GRscar_erratum > do-file uses original: "/scratch/public/jr_ra/GRscarring2024/erratum/rawdata/lnu04000000.csv" filesig(38777
> 77921:4243)

. import delimited using "`rawdata'/lnu04000000.csv" , clear varnames(1)
(14 vars, 74 obs)

. rename (jan-dec) ur#, addnumber

. foreach v of varlist ur* annual {
  2.   destring `v', replace
  3. }
ur1: all characters numeric; replaced as double
(1 missing value generated)
ur2: all characters numeric; replaced as double
(1 missing value generated)
ur3: all characters numeric; replaced as double
(1 missing value generated)
ur4: all characters numeric; replaced as double
(2 missing values generated)
ur5: all characters numeric; replaced as double
(2 missing values generated)
ur6: all characters numeric; replaced as double
(2 missing values generated)
ur7: all characters numeric; replaced as double
(2 missing values generated)
ur8: all characters numeric; replaced as double
(2 missing values generated)
ur9: all characters numeric; replaced as double
(2 missing values generated)
ur10: all characters numeric; replaced as double
(2 missing values generated)
ur11: all characters numeric; replaced as double
(2 missing values generated)
ur12: all characters numeric; replaced as double
(2 missing values generated)
annual: all characters numeric; replaced as double
(1 missing value generated)

. reshape long ur, i(year) j(month)
(j = 1 2 3 4 5 6 7 8 9 10 11 12)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations               74   ->   888         
Number of variables                  14   ->   4           
j variable (12 values)                    ->   month
xij variables:
                       ur1 ur2 ... ur12   ->   ur
-----------------------------------------------------------------------------

. gen yearmo=ym(year, month)

. keep yearmo ur annual

. drop if ur==. & annual==.
(9 observations deleted)

. rename ur ur_nat_u

. rename annual ur_nat_annual

. tempfile ur_u

. save `ur_u'
file /tmp/St2868349.000005 saved as .dta format

. merge 1:1 yearmo using `ur_s', nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                            12
        from master                        12  
        from using                          0  

    Matched                               867  
    -----------------------------------------

. tempfile ur_u_s

. save `ur_u_s'
file /tmp/St2868349.000006 saved as .dta format

. 
. **** LOAD IN NATIONAL EMPLOYMENT-POPULATION RATIO (EPR) *****
. * Downloaded from https://data.bls.gov/cgi-bin/srgate
. * Most recent download 25/08/2019
. * Series Id:    LNS12300000                             
. * Seasonally Adjusted                                   
. * Series title: (Seas) Employment-Population Ratio                              
. * Labor force status:   Employment-population ratio                             
. * Type of data: Percent or rate                         
. * Age:  16 years and over                               
. * Years:1948 to 2019
. *
. 
. if `doasproject'==1 project, original(`rawdata'/lns12300000.csv)
project GRscar_erratum > do-file uses original: "/scratch/public/jr_ra/GRscarring2024/erratum/rawdata/lns12300000.csv" filesig(10654
> 54991:4771)

. import delimited using "`rawdata'/lns12300000.csv" , clear varnames(1)
(13 vars, 73 obs)

. *drop if year==2018
. rename (jan-dec) epr#, addnumber

. foreach v of varlist epr* {
  2.   destring `v', replace
  3. }
epr1 already numeric; no replace
epr2 already numeric; no replace
epr3 already numeric; no replace
epr4: all characters numeric; replaced as double
(1 missing value generated)
epr5: all characters numeric; replaced as double
(1 missing value generated)
epr6: all characters numeric; replaced as double
(1 missing value generated)
epr7: all characters numeric; replaced as double
(1 missing value generated)
epr8: all characters numeric; replaced as double
(1 missing value generated)
epr9: all characters numeric; replaced as double
(1 missing value generated)
epr10: all characters numeric; replaced as double
(1 missing value generated)
epr11: all characters numeric; replaced as double
(1 missing value generated)
epr12: all characters numeric; replaced as double
(1 missing value generated)

. reshape long epr, i(year) j(month)
(j = 1 2 3 4 5 6 7 8 9 10 11 12)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations               73   ->   876         
Number of variables                  13   ->   3           
j variable (12 values)                    ->   month
xij variables:
                    epr1 epr2 ... epr12   ->   epr
-----------------------------------------------------------------------------

. gen yearmo=ym(year, month)

. keep yearmo epr

. drop if epr==.
(9 observations deleted)

. rename epr epr_nat_s

. tempfile epr_s

. save `epr_s'
file /tmp/St2868349.000007 saved as .dta format

. merge 1:1 yearmo using `ur_u_s', nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                            12
        from master                         0  
        from using                         12  

    Matched                               867  
    -----------------------------------------

. format yearmo %tm

. 
. * Employment to Population Ration
. * current and 2007 peak
. di epr_nat_s[_N]
.

. sum epr_nat_s if yofd(dofm(yearmo)) == 2007

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   epr_nat_s |         12      62.975    .2261335       62.7       63.3

. 
. * New generate 3 year rolling average for unemployment rate - 10/26/2017
. gen year=yofd(dofm(yearmo))

. gen ur_nat_3yr_avg = ((ur_nat_annual + ur_nat_annual[_n+12] + ur_nat_annual[_n+24])/3) if year<=2014
(75 missing values generated)

. drop year

. label var ur_nat_3yr_avg "3 year average unemployment rate"

. 
. save `prepdata'/`dofile'_national.dta, replace
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/unrate_national.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/unrate_national.dta saved

. if `doasproject'==1 project, creates(`prepdata'/`dofile'_national.dta)
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/unrate_national.dta" filesig(1052845
> 851:51188)

. 
. 
. *** LOAD STATE UNEMPLOYMENT DATA ***
. 
. **Downloaded from https://download.bls.gov/pub/time.series/la/
. **Most recent download 4/14/20
. **Footnote codes:
. **footnote_code footnote_text
. **A     Area boundaries do not reflect official OMB definitions.        
. **B     Reflects revised population controls, model reestimation, and new seasonal adjustment.  
. **C     Corrected.      
. **D     Reflects revised population controls and model reestimation.    
. **N     Not available.  
. **P     Preliminary.    
. **R     Data were subject to revision on April 21, 2017.        
. **S     Reflects new population controls and revised seasonal adjustment.       
. **T     Reflects new population controls.
. *****
. 
. if `doasproject'==1 project, original(`rawdata'/la.data.3.AllStatesS.txt)
project GRscar_erratum > do-file uses original: "/scratch/public/jr_ra/GRscarring2024/erratum/rawdata/la.data.3.AllStatesS.txt" file
> sig(975020712:9049359)

. import delimited `rawdata'/la.data.3.AllStatesS.txt, clear
(5 vars, 164,300 obs)

. *drop if year==2019
. gen fipsst=real(substr(series_id, 6,2))

. keep if fipsst<=56
(2,120 observations deleted)

. gen measure=real(substr(series_id, 20,1))

. keep if measure==3
(135,150 observations deleted)

. drop series_id measure

. gen mo=real(substr(period,2,.))

. gen yearmo=ym(year, mo)

. format yearmo %tm

. drop year mo period

. rename value ur_st_s

. rename footnote_codes fn_ur_st_s

. tempfile ur_state_s

. save `ur_state_s'
file /tmp/St2868349.000008 saved as .dta format

. 
. if `doasproject'==1 project, original(`rawdata'/la.data.2.AllStatesU.txt)
project GRscar_erratum > do-file uses original: "/scratch/public/jr_ra/GRscarring2024/erratum/rawdata/la.data.2.AllStatesU.txt" file
> sig(650570022:11410668)

. import delimited `rawdata'/la.data.2.AllStatesU.txt, clear
(5 vars, 207,214 obs)

. *drop if year==2019
. gen fipsst=real(substr(series_id, 6,2))

. keep if fipsst<=56
(2,296 observations deleted)

. gen measure=real(substr(series_id, 20,1))

. keep if measure==3
(175,644 observations deleted)

. drop series_id measure

. gsort fipsst year -period

. by fipsst year: assert period[1]=="M13" | year==2020

. by fipsst year: gen ur_st_annual=value[1] if period[1]=="M13"
(102 missing values generated)

. drop if period=="M13"
(2,244 observations deleted)

. gen mo=real(substr(period,2,.))

. gen yearmo=ym(year, mo)

. format yearmo %tm

. drop year mo period

. rename value ur_st_u

. rename footnote_codes fn_ur_st_u

. merge 1:1 fipsst yearmo using `ur_state_s', assert(3) nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            27,030  
    -----------------------------------------

. 
. * New generate 3 year rolling average for unemployment rate - 10/26/2017
. gen year=yofd(dofm(yearmo))

. sort fipsst year

. gen ur_st_3yr_avg = ((ur_st_annual + ur_st_annual[_n+12] + ur_st_annual[_n+24])/3) if year<=2014
(3,162 missing values generated)

. drop year

. label var ur_st_3yr_avg "3 year average unemployment rate (state)"

. 
. save `prepdata'/`dofile'_state.dta, replace
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/unrate_state.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/unrate_state.dta saved

. if `doasproject'==1 project, creates(`prepdata'/`dofile'_state.dta)
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/unrate_state.dta" filesig(3849316085
> :1384205)

. 
. 
. 
end of do-file
      name:  plog_7
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/prepare/unrate.log
  log type:  text
 closed on:  27 Nov 2024, 13:52:52
------------------------------------------------------------------------------------------------------------------------------------
